/**
 * Created by Mars on 2016/12/13.
 */
import React, {Component} from 'react';
import{
    StyleSheet,
    Navigator,
    View,
    Text,
    Image,
    TouchableOpacity,
    BackAndroid,
    Platform
} from 'react-native';

import Header from '../component/Header';
import WriteResume from './WriteResume';

export default class Resume extends Component {
    _backtoMeTab = () => {
        const {navigator} = this.props;
        if (navigator) {
            navigator.pop();
        }
    };

    componentWillMount() {
        if (Platform.OS === 'android') {
            BackAndroid.addEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    componentWillUnmount() {
        if (Platform.OS === 'android') {
            BackAndroid.removeEventListener('hardwareBackPress', this.onBackAndroid);
        }
    }

    /* Android返回键执行的操作 被之前BackAndoid组件调用*/
    onBackAndroid = () => {
        const {navigator} = this.props;
        const routers = navigator.getCurrentRoutes();
        if (routers.length > 1) {
            navigator.pop();
            return true;
        }
        return false;
    };

    _gotoWriteResume = () => {
        const {navigator}=this.props;
        if (navigator) {
            navigator.push({
                name: 'WriteResume',
                component: WriteResume
            })
        }
    };

    render() {
        return (
            <View style={styles.container}>
                <Header name="简历"
                        function={this._backtoMeTab}/>

                <View style={styles.body}>
                    <View style={styles.above}>
                        <Image style={styles.img} source={require('../Images/nothing.png')}></Image>

                        <Text>
                            无任何简历信息
                        </Text>
                    </View>

                    <View style={styles.below}>
                        <TouchableOpacity onPress={this._gotoWriteResume}>
                            <View style={styles.button}>
                                <Text style={styles.text}>
                                    添加简历
                                </Text>
                            </View>
                        </TouchableOpacity>
                    </View>
                </View>
            </View>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: "center",
        backgroundColor: "#FFFFFF",
    },
    body: {
        flex: 10,
        alignItems: "center",
    },
    above: {
        flex: 1,
        flexDirection: "column",
        alignItems: "center",
    },
    img: {
        width: 200,
        height: 200,
        margin: 20,
    },
    below: {
        flex: 1,
    },
    button: {
        flexDirection: "column",
        justifyContent: "center",
        marginTop: 40,
        alignItems: "center",
        width: 150,
        height: 30,
        backgroundColor: "#2E7CDE",
        borderRadius: 5,
    },
    text: {
        fontSize: 20,
        color: "#FFFFFF",
    }
});